package sz.szsmk.citizencard.ui.newversion.fragment

import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.PopupWindow
import androidx.core.view.ViewCompat
import kotlinx.android.synthetic.main.fragment_logoffsecondpage.*
import sz.szsmk.citizencard.DaggerApplication
import sz.szsmk.citizencard.R
import sz.szsmk.citizencard.model.network.bean.response.BaseBean
import sz.szsmk.citizencard.mvp.BasePresenter
import sz.szsmk.citizencard.ui.adapter.PopRvAdapter
import sz.szsmk.citizencard.ui.dzsmkfragment.AppBaseFragment
import sz.szsmk.citizencard.ui.newversion.bean.AppealTypeVo
import sz.szsmk.citizencard.ui.newversion.bean.AppealTypeVoListBean
import sz.szsmk.citizencard.ui.newversion.bean.InsertAppealInfoBean
import sz.szsmk.citizencard.ui.newversion.dialog.LogOutDialog
import sz.szsmk.citizencard.ui.newversion.fragment.adapter.AppealTypeAdapter
import sz.szsmk.citizencard.ui.newversion.fragment.presenter.LogoffPresenter
import sz.szsmk.citizencard.ui.newversion.fragment.view.LogoffMvpView
import sz.szsmk.citizencard.util.ACache
import java.util.*
import javax.inject.Inject

/**
 *  author : hyt
 *  date : 2020/8/12
 *  description :
 */
class LogoffSecondPageFragment : AppBaseFragment() , LogoffMvpView {

    @Inject
    lateinit var presenter: LogoffPresenter

    override fun getTopTitle() = null

    override fun initPresenters(): Array<BasePresenter<*>>? {
        return arrayOf(presenter)
    }

    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
    ): View? {
        val root = inflater.inflate(R.layout.fragment_logoffsecondpage, container, false)
        component.inject(this)
        return root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        btn_logoff.setOnClickListener {

            if(et_remark.text.length>500){
                showToast("文本字数超出限制")
                return@setOnClickListener
            }
            if(et_remark.text.isEmpty()){
                showToast("请输入注销原因")
                return@setOnClickListener
            }

            var dialog = context?.let { it1 -> LogOutDialog(it1) }
            dialog?.iLogOffDialogClick = iLogOffDialogClick
            dialog?.show()
        }

    }

    private var iLogOffDialogClick = object:LogOutDialog.ILogOffDialogClick{
        override fun onClick() {

            var bean = InsertAppealInfoBean(
                    ACache.get(DaggerApplication.getIns()).getAsString("access_token")  ,
                    et_phone.text.toString().trim(),
                    "",
                    appealType,
                    et_remark.text.toString().trim(),
                    ""
            )
            presenter.insertAppealInfo(bean)

        }
    }
    var appealType = 1
    var appealTypeList  = mutableListOf<AppealTypeVo>()

    override fun AppealTypeVoListonSuccess(baseBean: AppealTypeVoListBean) {
        appealTypeList.clear()
        appealTypeList.addAll(baseBean.appealTypeVoList)
//        sp_logoffType.adapter = context?.let { AppealTypeAdapter(it,appealTypeList) }
    }

    override fun onFail(baseBean: BaseBean) {
        showToast(baseBean.message)
    }

    override fun onLogoffSuccess(baseBean: BaseBean) {
        showToast(baseBean.message)
    }





}